package work728.work3;

public class Computer {
  USB usb[] = new USB[10];
  int num;

  public void add(USB u){
    boolean pd = false;
    for (int i = 0; i <10 ; i++) {
      if (usb[i] == null){
        usb[i] = u;
        pd = true;
        break;
      }
    }
    if (pd == false){
      System.out.println("数组已满");
    }

  }

  public void powerOn(){
    for (USB  u:usb) {
      if (u!=null){
        u.trunOn();
      }
    }
    System.out.println("计算机开机成功");
  }

  public void  powerOff(){
    for (USB  u:usb) {
      if (u!=null){
        u.turnOff();
      }
    }
    System.out.println("计算机关机机成功");
    }

  public static void main(String[] args) {
    Computer computer = new Computer();
    computer.add(new Mic());
    computer.add(new Mouse());
    computer.add(new KeyBorad());
    computer.powerOn();
    computer.powerOff();
  }
  }

